package com.superteam.zzl.Des;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.superteam.zzl.activity.R;

import java.util.List;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

/**
 * Created by Administrator on 2017/1/11.
 */
public class PutongAdapter  extends BaseAdapter{
    private Context context;
    private List<Object> olist;
    private List<Putong2.Data.Recommend_pin_list.Entertainment>list;

    public PutongAdapter(Context context, List<Object> olist) {
        this.context = context;
        this.olist = olist;
    }

    @Override
    public int getCount() {
        return olist.size();
    }

    @Override
    public Object getItem(int position) {
        return olist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder vh;
        if (convertView==null){
            vh=new ViewHolder();
            convertView=View.inflate(context,R.layout.pu_gv_item,null);
            vh.iv=(ImageView)convertView.findViewById(R.id.pu_iv);
            vh.tv=(TextView)convertView.findViewById(R.id.pu_tv);
            convertView.setTag(vh);
        }else {
            vh=(ViewHolder)convertView.getTag();
        }
        Object object=olist.get(position);
        if (object instanceof Putong2.Data.Recommend_pin_list.Entertainment) {
            Putong2.Data.Recommend_pin_list.Entertainment pdre = (Putong2.Data.Recommend_pin_list.Entertainment) object;
            vh.tv.setText(pdre.title);
//            vh.iv.setTag(pdre.cover_image);
//            new BitMapAsyncTask(context, new BitMapAsyncTask.CallBack() {
//                @Override
//                public void sendBitMap(String url, Bitmap bitmap) {
//                    if (url.equals(vh.iv.getTag())){
//                        vh.iv.setImageBitmap(bitmap);
//                    }
//                }
//            }).execute(pdre.cover_image);
//        if (list.get(position).cover_image.length() > 5) {
            final BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
            Glide.with(context).load(pdre.cover_image).bitmapTransform(new RoundedCornersTransformation(bitmapPool,10,0)).into(vh.iv);
           // }
        }
        return convertView;
    }
    class ViewHolder{
        ImageView iv;
        TextView tv;
    }
}
